/*
 * @Author: 孙开源 && sunkaiyuan@namenode.cn
 * @Date: 2023-02-07 08:50:22
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @LastEditTime: 2023-11-10 15:08:33
 * @Description:
 *
 */
import { VXETable } from "vxe-table";
import formatAuxiliaryDyeing from "./components/formatAuxiliaryDyeing.vue";
import formatFinanceNumber from "./components/formatFinanceNumber.vue";
import formatFinanceAccounting from "./components/formatFinanceAccounting.vue";
import formatImage from "./components/formatImage.vue";
import designerBarcode from "./components/designerBarcode.vue";
import formatColor from "./components/formatColor.vue";

VXETable.renderer.add("imageCellRender", {
	// 默认显示模板
	renderDefault(renderOpts, params) {
		var field = renderOpts.attrs.field;
		var thumbnail_field = "thumb_" + field;
		let src = params.row[thumbnail_field] ?? params.row[field];

		let srcList = params.visibleData
			.filter((v) => {
				return v[field];
			})
			.map((v) => {
				return v[field];
			});
		return (
			<formatImage
				src={src}
				srcList={srcList}
				index={params.$rowIndex}
			></formatImage>
		);
	},
	// 导出模板，例如导出插槽中自定义的内容
	exportMethod(params) {
		const { row } = params;
		return row;
	},
});
VXETable.renderer.add("colorRender", {
	// 默认显示模板
	renderDefault(renderOpts, params) {
		var field = renderOpts.attrs.field;
		let src = params.row[field];
		return (
			<formatColor
				color={src}
				row={params.row}
				gridEvents={renderOpts.gridEvents}
			></formatColor>
		);
	}
});
VXETable.renderer.add("dragRender", {
	// 默认显示模板
	renderDefault() {
		return (
			<span class="drag-btn">
				<el-icon size={14}>
					<ElIconRank />
				</el-icon>
			</span>
		);
	},
});
VXETable.renderer.add("designerBarcode", {
	// 默认显示模板
	renderDefault(renderOpts, params) {
		const { row } = params;
		return <designerBarcode fileid={row.id} filename={row.filename} />;
	},
});
VXETable.renderer.add("financeNumber", {
	// 默认显示模板
	renderDefault(renderOpts, params) {
		const { row, column } = params;
		return (
			<formatFinanceNumber
				params={params}
				v-model={row[column.field]}
			></formatFinanceNumber>
		);
	},
	exportMethod(params) {
		const { row, column } = params
		return row[column.field];
	}

});

VXETable.renderer.add("formatAuxiliaryDyeing", {
	// 默认显示模板
	renderDefault(renderOpts, params) {
		return <formatAuxiliaryDyeing params={params}></formatAuxiliaryDyeing>;
	},
});

VXETable.renderer.add("formatFinanceAccounting", {
	// 默认显示模板
	renderDefault(renderOpts, params) {
		return (
			<formatFinanceAccounting params={params}></formatFinanceAccounting>
		);
	},
});
